Repository navigation
Added a check for characters which an API key cannot contain - #1227
Merged
SommerEngineering merged 13 commits intoNov 24, 2026
Merged
SommerEngineering merged 13 commits into
SommerEngineering merged 13 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Users paste API keys from web pages, documents, or password managers, and sometimes characters come along which an HTTP header cannot carry: a non-breaking space, a zero-width space, a line break, or a typographic quotation mark. .NET refuses such a key only while sending, with messages such as "Request headers must contain only ASCII characters.", which users cannot act on; for transcriptions, they only learned that AI Studio could not transcribe. No input checked more than whether a key was empty.
What changes:
APIKeyValidationinTools/Validation/removes spaces and line breaks around a key and reports whitespace inside it, invisible characters, and every other character beyond printable ASCII, naming that character. It checks per grapheme cluster, so a decomposedäcounts as one character. It changes a key in no other way and never writes it into a log or a message.RustService.SetAPIKeystores every key trimmed.TryValidateConfiguration. Otherwise, a bad Tavily key would switch off the whole web search, SearXNG included.BaseProvider.DecryptAPIKeyreplaces the twelve places where providers decrypted a key themselves, and the model loading checks its key, too. Such a request fails before it is sent, with the new failure reasonINVALID_API_KEY_CHARACTERSand a message which asks to enter the key again or to contact the IT department. A key which is empty after trimming fails as a missing key instead of sendingBearer. Tavily and Staan fail the same way, and the web search then asks its other services.Authorizationheader without parsing it. A guard test keeps every provider from parsing a key as anAuthorizationheader.app.cssinstead of an opt-in class. The same goes for the list of issues and the API key prompt.ERI tokens and passwords follow in a separate pull request, with the same check.
Related proposal or issue
None. Found while reviewing #1224.
How did you test it?
dotnet run -- verify: 7,312 .NET tests, the trim smoke test, 379 Rust tests, Clippy, and the model sources.Authorizationheader.Wiki
Users, page "Troubleshooting" (German: "Fehlerbehebung"), table "A provider doesn't answer": a new row for the messages about a space or a line break, an invisible character, or a character which an API key cannot contain. Copy the key once more from the page of the provider, or type it, and enter it again. AI Studio removes spaces and line breaks around a key by itself. If the organization provides the key, contact the IT department. Requires AI Studio v26.11.2 or newer.
IT departments, page "Enterprise Troubleshooting", section "API keys are missing": AI Studio leaves out a decrypted key with a character which an API key cannot contain, such as an invisible character or a typographic quotation mark, and writes a warning to the log, which names the kind of character but not the key. Spaces and line breaks around a key are no problem. Requires AI Studio v26.11.2 or newer.
Both are prepared for the release.
Required statements
Credits (optional)